﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MyPublisher.Framework
{
    public abstract class PublishProvider
    {
        protected PublishProvider()
        {
        }

        public abstract Publishing Publish(Package package);
    }

    public class ZipPublishProvider : PublishProvider
    {
        public override Publishing Publish(Package package)
        {
            throw new NotImplementedException();
        }
    }

    public class ArchivePublishProvider : PublishProvider
    {
        public Location ArchiveLocation { get; set; }

        public ArchivePublishProvider(Location archiveLocation)
        {
            this.ArchiveLocation = archiveLocation;
        }

        public override Publishing Publish(Package package)
        {
            string directory = Path.Combine(ArchiveLocation.Address, package.Name);
            Directory.CreateDirectory(directory);
            foreach (Content content in package.Contents)
            {
                string file = Path.Combine(directory, content.Name);
                if (content.Path != file)
                {
                    System.IO.File.Copy(content.Path, file, true);
                }
            }

            return new Publishing(ArchiveLocation,@"\") { Package = package };
        }
    }
}
